from rest_framework.renderers import JSONRenderer


class MarketJSONRenderer(JSONRenderer):
    def render(self, data, accepted_media_type=None, renderer_context=None):

        if renderer_context['response'].status_code == 401:
            res = {
                'code': '5001',
                'msg': '您还未登陆或登陆已经过期！',
            }
            return super().render(res)
        code = data.pop('code', 8000)
        res = {'code': code}
        if code == '5000':
            res = {
                'msg':""
            }
        if code == '5002':
            res['data'] = {}
        if code == '4000':
            res['data'] = data.pop('data', {})
        renderer_context['response'].status_code = 200
        return super().render(res)

